#include "DictComp.h"
#include "IVisitor.h"

DictComp::DictComp(const exprTypePtr& key, const exprTypePtr& value, const ComprehensionTypeList& generators, int nodeId):
    exprType(nodeId),
    _key(key),
    _value(value),
    _generators(generators)
{
}
    
DictComp::~DictComp()
{
    _generators.clear();
}
    
Ast::AstTypes DictComp::type() const
{
    return Ast::DictComp;
}
    

exprTypePtr DictComp::key()
{
    return _key;
}

void DictComp::setKey(const exprTypePtr& key)
{
    _key = key;
}

exprTypePtr DictComp::value()
{
    return _value;
}

void DictComp::setValue(const exprTypePtr& value)
{
    _value = value;
}

ComprehensionTypeList DictComp::generators()
{
    return _generators;
}

void DictComp::setGenerators(const ComprehensionTypeList& generators)
{
    _generators = generators;
}

    
QString DictComp::toString() const
{
    return QString("DictComp[key=%1, value=%2, generators=%3]").
                arg(_key ? _key->toString():"").
                arg(_value ? _value->toString():"").
                arg(_generators.toString());
}
    
void DictComp::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitDictComp(node.dynamicCast<DictComp>());
}
    
void DictComp::traverse(IVisitor* visitor)
{
    if (_key != NULL)
        _key->accept(visitor, _key);
    if (_value != NULL)
        _value->accept(visitor, _value);
    _generators.traverse(visitor);
}